﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Fiddler;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        delegate void UpdateUI();
        public Form1()
        {
            InitializeComponent();
            textBox1.Text = DateTime.Now.ToLongDateString() + " ms:" + DateTime.Now.Ticks;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Fiddler.FiddlerApplication.BeforeRequest += FiddlerApplication_BeforeRequest;
            Fiddler.FiddlerApplication.Startup(0, FiddlerCoreStartupFlags.Default);
        }

        void FiddlerApplication_BeforeRequest(Session oSession)
        {
            string s = oSession.url;
            if (s.Contains(".core.windows.net"))
            {
                oSession.url = s.Replace(".core.windows.net", ".core.chinacloudapi.cn");
            }

            //listBox1.Invoke(new UpdateUI(() =>
            //{

            //    listBox1.Items.Add(oSession.url);
            //    oSession.url = s.Replace(".core.windows.net", "core.chinacloudapi.cn");



            //}));

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Fiddler.FiddlerApplication.Shutdown();
        }
    }
}
